<template>
  <el-row type="flex" justify="sapce-betwen" align="middle" style="height: 40px; width: 100%;">
    <!-- 左侧内容 -->
    <el-col>
      {{ obj.name }}
    </el-col>
    <!-- 右侧内容 -->
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ obj.manager }}</el-col>
        <el-col>
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRooterNode" command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRooterNode" command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartmentsAPI } from '@/api'
export default {
  name: 'TreeNode',
  props: {
    obj: {
      type: Object,
      required: true
    },
    isRooterNode: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleCommand(command) {
      if (command === 'add') {
        this.$emit('addPopshow', this.obj)
      // eslint-disable-next-line no-empty
      } else if (command === 'edit') {
        this.$emit('editDepts', this.obj)
      } else {
        this.$confirm('确定要删除吗？').then(() => {
          return delDepartmentsAPI(this.obj.id)
        }).then(() => {
          this.$emit('delDepts')
        })
      }
    }
  }
}
</script>

<style>

</style>
